package com.gadgets.framework.common.validator;

import com.gadgets.framework.common.constant.GadgetsExceptionConstant;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.StringUtils;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-11-02
 * 
 */
public abstract class AbsForamtValidatorTrigger<T> {

    public void excute(T target) throws GadgetsServiceException {
        String result = validate(target);
        if(!StringUtils.isBlank(result)){
            throw new GadgetsServiceException(GadgetsExceptionConstant.VALIDATE_ERROR,result);
        }
    }

    /**
     * 校验方法
     * @param target    校验目标
     * @return          校验结果
     */
    protected abstract String validate(T target);

}
